home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / src / cfe / cfe.l < prev    next >
Text File  |  1992-01-23  |  4KB  |  132 lines

  1.  /* --------------------------------------------------------------------------
  2.   * Copyright 1992 by Forschungszentrum Informatik (FZI)
  3.   *
  4.   * You can use and distribute this software under the terms of the licence
  5.   * you should have received along with this program.
  6.   * If not or if you want additional information, write to
  7.   * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  8.   * D-7500 Karlsruhe 1, Germany.
  9.   * --------------------------------------------------------------------------
  10.   */
  11. %{
  12. extern "C" int yywrap();
  13. extern "C" int yylook();
  14. extern "C" int yyback(int*, int);
  15. extern "C" YYSTYPE yylval;
  16. extern "C" void yyecho();
  17.  
  18. static int name_or_keyword ()
  19. {  switch (yytext[0])
  20.    {  case 'a':
  21.          if (streql (yytext, "abstract")) return abstract_tok;
  22.      break;
  23.       case 'c':
  24.          if (streql (yytext, "class")) return class_tok;
  25.      break;
  26.       case 'd':
  27.          if (streql (yytext, "definite")) return definite_tok;
  28.      break;
  29.       case 'e':
  30.          if (streql (yytext, "enum")) return enum_tok;
  31.          if (streql (yytext, "extern")) return extern_tok;
  32.      break;
  33.       case 'f':
  34.          if (streql (yytext, "friend")) return friend_tok;
  35.      break;
  36.       case 'l':
  37.          if (streql (yytext, "local")) return local_tok;
  38.      break;
  39.       case 'o':
  40.          if (streql (yytext, "operator")) return operator_tok;
  41.      break;
  42.       case 'p':
  43.          if (streql (yytext, "private")) return private_tok;
  44.          if (streql (yytext, "protected")) return protected_tok;
  45.          if (streql (yytext, "public")) return public_tok;
  46.      break;
  47.       case 's':
  48.          if (streql (yytext, "set")) return set_tok;
  49.          if (streql (yytext, "schema")) return schema_tok;
  50.          if (streql (yytext, "static")) return static_tok;
  51.      break;
  52.       case 't':
  53.          if (streql (yytext, "typedef")) return typedef_tok;
  54.      break;
  55.       case 'u':
  56.          if (streql (yytext, "union")) return union_tok;
  57.      break;
  58.       case 'w':
  59.          if (streql (yytext, "with")) return with_tok;
  60.      break;
  61.       default:
  62.      break;
  63.    }
  64.    return name_tok;
  65. }
  66.  
  67. %}
  68.  
  69. letter    [a-zA-Z_]
  70. digit    [0-9]
  71. diglet    [a-zA-Z_0-9]
  72.  
  73. %START comment
  74. %%
  75.  
  76. "/*"            {yyecho(); BEGIN comment;}
  77. <comment>[^\n*]*\n    {yyecho();}
  78. <comment>[^\n*]*"*/"    {yyecho(); BEGIN 0;}
  79. <comment>[^\n*]*"*"    {yymore();}
  80.  
  81. "//"[^\n]*\n        {yyecho();}
  82.  
  83. "<"            {yyecho(); return l_abr_tok;}
  84. ">"            {yyecho(); return r_abr_tok;}
  85. "&"            {yyecho(); return ampersand_tok;}
  86. "&="            {yyecho(); return ampersand_assign_tok;}
  87. "&&"            {yyecho(); return and_tok;}
  88. "="            {yyecho(); return assign_tok;}
  89. "|"            {yyecho(); return bar_tok;}
  90. "|="            {yyecho(); return bar_assign_tok;}
  91. "["            {yyecho(); return l_br_tok;}
  92. "]"            {yyecho(); return r_br_tok;}
  93. "{"            {yyecho(); return l_brc_tok;}
  94. "}"            {yyecho(); return r_brc_tok;}
  95. "^"            {yyecho(); return circumflex_tok;}
  96. "^="            {yyecho(); return circumflex_assign_tok;}
  97. ":"            {yyecho(); return colon_tok;}
  98. ","            {yyecho(); return comma_tok;}
  99. "=="            {yyecho(); return equal_tok;}
  100. ">="            {yyecho(); return greater_equal_tok;}
  101. "<="            {yyecho(); return less_equal_tok;}
  102. "-"            {yyecho(); return minus_tok;}
  103. "-="            {yyecho(); return minus_assign_tok;}
  104. "!="            {yyecho(); return not_equal_tok;}
  105. "||"            {yyecho(); return or_tok;}
  106. "("            {yyecho(); return l_par_tok;}
  107. ")"            {yyecho(); return r_par_tok;}
  108. "%"            {yyecho(); return percent_tok;}
  109. "%="            {yyecho(); return percent_assign_tok;}
  110. "+"            {yyecho(); return plus_tok;}
  111. "+="            {yyecho(); return plus_assign_tok;}
  112. ">>="            {yyecho(); return rshift_assign_tok;}
  113. "<<="            {yyecho(); return lshift_assign_tok;}
  114. "/"            {yyecho(); return slash_tok;}
  115. "/="            {yyecho(); return slash_assign_tok;}
  116. "*"            {yyecho(); return star_tok;}
  117. "*="            {yyecho(); return star_assign_tok;}
  118. ";"            {yyecho(); return semicolon_tok;}
  119. "!"            {yyecho(); return exclam_tok;}
  120. {digit}+        {yyecho();
  121.              yylval.i = atoi (yytext);
  122.              return number_tok;}
  123. {letter}({diglet})*    {yyecho();
  124.              int tok = name_or_keyword();
  125.              if (tok == name_tok)
  126.              {  yylval.s = new char[yyleng+1];
  127.                 strcpy (yylval.s, yytext);
  128.              }
  129.              return tok;}
  130. [ \014\n\t]        {yyecho();}
  131. .            {yyecho(); cfe_error (err_USE, err_CFE_LEXICAL_ERROR);}
  132.